import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { SELECT, RECYCLE_BIN, CRUD, RECYCLE } from '@/sheep/request/crud';

const route = {
  path: 'supply/goods',
  name: 'shop.admin.supply.goods',
  component: Content,
  meta: {
    title: '商品管理',
  },
  children: [
    {
      path: 'goods',
      name: 'shop.admin.supply.goods.goods',
      component: () => import('./goods/index.vue'),
      meta: {
        title: '商品库',
      },
    },
    {
      path: 'stockwarning',
      name: 'shop.admin.supply.goods.stockwarning',
      component: () => import('./stockWarning/index.vue'),
      meta: {
        title: '库存预警',
      },
    },
    {
      path: 'stocklog',
      name: 'shop.admin.supply.goods.stocklog',
      component: () => import('./stockLog.vue'),
      meta: {
        title: '库存记录',
      },
    },
    {
      path: 'service',
      name: 'shop.admin.supply.goods.service',
      component: () => import('./service/index.vue'),
      meta: {
        title: '服务保障',
      },
    },
    {
      path: 'comment',
      name: 'shop.admin.supply.goods.comment',
      component: () => import('./comment/index.vue'),
      meta: {
        title: '客户评价',
      },
    },
  ],
};

const api = {
  goods: {
    ...CRUD('shop/admin/goods/goods'),
    ...RECYCLE('shop/admin/goods/goods'),
    select: (params, type = 'page') =>
      request({
        url: `shop/admin/goods/goods/select?type=${type}`,
        method: 'GET',
        params,
      }),
    activitySelect: (params) =>
      request({
        url: 'shop/admin/goods/goods/activitySelect',
        method: 'GET',
        params,
      }),
    getType: () =>
      request({
        url: '/shop/admin/goods/goods/getType',
        method: 'GET',
      }),
    getSkuPrice: (id) =>
      request({
        url: '/shop/admin/goods/skuPrice/' + id,
        method: 'GET',
      }),
    updateSkuPrice: (id, status) =>
      request({
        url: '/shop/admin/goods/skuPrice/' + id,
        method: 'PUT',
        params: {
          status: status,
        },
      }),
    addStock: (id, data) =>
      request({
        url: 'shop/admin/goods/goods/addStock/' + id,
        method: 'POST',
        data,
      }),
	  upload: (data) =>
	    request({
	      url: 'shop/admin/goods/goods/upload',
	      method: 'POST',
	      data,
	    }),
  },
  stockWarning: {
    ...CRUD('shop/admin/goods/stockWarning', ['list']),
    recyclebin: (params) => RECYCLE_BIN('shop/admin/goods/stockWarning', params),
    addStock: (id, params) =>
      request({
        url: 'shop/admin/goods/stockWarning/addStock/' + id,
        method: 'POST',
        params,
      }),
  },
  stockLog: (params) =>
    request({
      url: 'shop/admin/goods/stockLog',
      method: 'GET',
      params,
    }),
  service: {
    ...CRUD('shop/admin/goods/service'),
    select: (params) => SELECT('shop/admin/goods/service', params),
  },
  comment: {
    ...CRUD('shop/admin/goods/comment'),
    ...RECYCLE('shop/admin/goods/comment'),
    reply: (id, params) =>
      request({
        url: 'shop/admin/goods/comment/reply/' + id,
        method: 'PUT',
        params,
      }),
  },
};

export { route, api };
